package com.xiaozhaovip.demo.Enum;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 活动城市枚举
 *
 * @author Cauli
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum YueQiLaiCityEnum {
    XianShang(0, "线上"),
    BeiJing(11, "北京"),
    ShangHai(21, "上海"),
    GuangZhou(31, "广州"),
    ShenZhen(41, "深圳"),
    XiAn(51, "西安"),
    NanJing(61, "南京");

    private int id;

    private String name;

    /**
     * 通过 id 得到城市
     *
     * @param id
     * @return
     */
    public static YueQiLaiCityEnum getById(int id) {
        for (YueQiLaiCityEnum cityEnum : YueQiLaiCityEnum.values()) {
            if (cityEnum.id == id) {
                return cityEnum;
            }
        }
        return null;
    }

    /**
     * 获取所有城市枚举
     *
     * @return
     */
    public static List<YueQiLaiCityEnum> getAllCities() {
        List<YueQiLaiCityEnum> list = new ArrayList<>();
        for (YueQiLaiCityEnum cityEnum : YueQiLaiCityEnum.values()) {
            list.add(cityEnum);
        }
        return list;
    }
}
